package com.chefu.upload.controller;


import com.chefu.upload.service.UploadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 上传控制器
 */
@RestController
@Slf4j
public class UploadController {

    @Autowired
    private UploadService uploadService;

    /**
     * 获取阿里云签名
     */
    @GetMapping("/signature")
    public ResponseEntity<Map<String,String>> getOssSigature(){
        log.info("进入签名方法");
        Map<String,String> resultMap =uploadService.getOssSigature();
        return ResponseEntity.ok(resultMap);
    }

    /**
     *本地图片上传测试
     */
    @PostMapping("/image")
    public ResponseEntity<String> uploadImage(@RequestParam("file") MultipartFile file){
        log.info("进入图片上传到本地服务器方法");
        String imageUrl = uploadService.uploadImage(file);
        return ResponseEntity.ok(imageUrl);
    }

}
